<template>
    <div>
        <!-- 顶部导航栏 -->
       <div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
            <div class="mui-scroll">
                <a :class="['mui-control-item', item.id == 0 ? 'mui-active':'']" v-for="item in imgcategory" :key="item.id" @tap="getimagesByCateId(item.id)">
                    {{item.title}}
                </a>
            </div>
        </div>

        <!-- 图片列表 -->
        <ul class="photolist">
            <router-link  v-for="(item,i) in imglist" :key="i" tag="li" :to="'/home/photolist/photoinfo/'+item.id">
                <img v-lazy="item.img_url">
                <div class="capture">
                    <h3 class="p_title">{{item.title}}</h3>
                    <div class="p_capture">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
import mui from '../../lib/mui/js/mui.min.js'
import { Toast } from 'mint-ui'
export default {
    created(){
        this.getimgcategory()
        this.getimagesByCateId(0)
    },
    mounted(){
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    },
    data(){
        return {
            imgcategory:[],
            imglist:[]
        }
    },
    methods:{
        // 获取图片分类数据
        getimgcategory(){
            this.$http.get('api/getimgcategory').then(result=>{
                if(result.body.status === 0){
                    var category = {
                        title:'全部',
                        id:0
                    }
                    this.imgcategory = result.body.message
                    this.imgcategory.unshift(category)
                } else {
                    Toast('获取图片分类数据失败')
                }
            })
        },
        getimagesByCateId(id){
            this.$http.get('api/getimages/'+id).then(result=>{
               if(result.body.status === 0) {
                    this.imglist = result.body.message
                } else {
                    Toast('获取图片列表失败')
                }
            })
        }
        
    }
    
}
</script>

<style lang="less" scoped>
* { touch-action: pan-y; }
    .mui-bar-tab .mui-tab-item1.mui-active {
      color: #007aff;
    }
.photolist {
    list-style: none;
    margin:0;
    padding: 10px;
    
    li {
        list-style: none;
        position: relative;
        margin-bottom: 10px;
        box-shadow: 0 0 9px #999;
        background-color: #ccc;
        text-align: center;
        img {
            width: 100%;
            vertical-align: middle;
        }
        img[lazy='loading'] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        .capture{
            position: absolute;
            bottom: 0;
            background:rgba(0,0,0,0.4);
            color: #fff;
            max-height: 84px;
            text-align: left;
            .p_title {
                font-size: 14px;
            }
            .p_capture{
                font-size: 13px;
            }
        }
    }
}
</style>